﻿using AutoMapper;
using MediatR;
using W.Carrier.Api.Application.Command;
using W.Carrier.Repostiory.Interface;

namespace W.Carrier.Api.Application.CommandHandler
{
    public class CarrierCreateCommandHandler:IRequestHandler<CarrierCreateCommand,int>
    {
        private readonly ICarrierInfoRepository _icarrierInfoRepository;
        private readonly IMapper _mapper;
        public CarrierCreateCommandHandler(ICarrierInfoRepository icarrierInfoRepository,IMapper mapper)
        {
            _icarrierInfoRepository = icarrierInfoRepository;
            _mapper = mapper;
        }

        public async Task<int> Handle(CarrierCreateCommand request, CancellationToken cancellationToken)
        {
            return await _icarrierInfoRepository.AddAsync(new Domain.CarrierInfo
            {
                CarrierId = request.CarrierId,
                CarrierNo = request.CarrierNo,
                CarrierName = request.CarrierName,
                CarrierRemarks = request.CarrierRemarks,
                officeId=request.officeId,
                userid=request.userid,
                CreateName=request.CreateName,
                CreateTime=DateTime.Now,
                IsDelete=false,
            });
        }
    }
}
